Graphics类
DrawTexture
- ToScreen
public void Dmainxture()
{
GL.PushMatrix();
//GL.LoadPixelMatrix();
GL.LoadPixelMatrix(0,Screen.width,Screen.height,0);
Graphics.DrawTexture(new Rect(0, 0, 200, 100), mainTexture);
GL.PopMatrix();
}
在Update中调用会被Camera渲染Clear掉,所以只能在OnGUI和OnPostRender中调用。但是如果将texture绘制到一个RenderTexture中则可以在Update中调用。
- ToTarget
public void DrawTextureToTarget()
{
Graphics.SetRenderTarget(target);
clearBuffer.Clear();
clearBuffer.ClearRenderTarget(true, true, clearColor);
Graphics.ExecuteCommandBuffer(clearBuffer);
GL.PushMatrix();
GL.LoadPixelMatrix(0, target.width, target.height, 0);
//GL.LoadPixelMatrix(0, target.width, 0, target.height);
Graphics.DrawTexture(new Rect(0, 0, target.width, target.height), mainTexture);
GL.PopMatrix();
}
Graphics.SetRenderTarget(target)
将绘制结果绘制在一个RenderTexture类型的变量target上,所以屏幕变换需要使用GL.LoadPixelMatrix(0, target.width, target.height, 0)
,此时可以在update中调用。
DrawMesh
- Update中调用
public void DrawMesh()
{
Graphics.DrawMesh(Graphics00Mesh.Instance.GetMesh(10, 5), Matrix4x4.identity, material, 0);
//Graphics.DrawMesh(Graphics00Mesh.Instance.GetMesh(10, 5), center,Quaternion.identity, material, 0);
}
- OnPostRender中调用
只能使用Graphics.DrawMeshNow
方法。
- ToScreen
private void DrawToScreen()
{
drawBuffer.Clear();
drawBuffer.ClearRenderTarget(true, true, clearColor);
Graphics.ExecuteCommandBuffer(drawBuffer);
drawBuffer.DrawMesh(Graphics00Mesh.Instance.GetMesh(triCount, radius), Matrix4x4.identity, mat);
Graphics.ExecuteCommandBuffer(drawBuffer);
}
- ToTarget
private void DrawToTarget()
{
GL.PushMatrix();
Graphics.SetRenderTarget(target);
GL.LoadPixelMatrix(0, target.width, 0, target.height);
drawBuffer.Clear();
drawBuffer.ClearRenderTarget(true, true, clearColor);
Graphics.ExecuteCommandBuffer(drawBuffer);
drawBuffer.DrawMesh(Graphics00Mesh.Instance.GetMesh(triCount, radius), Matrix4x4.identity, mat);
Graphics.ExecuteCommandBuffer(drawBuffer);
GL.PopMatrix();
}
参考文章
https://www.cnblogs.com/llstart-new0201/p/12315716.html